package com.bjpowernode.boss.common.utils;

import org.springframework.util.ObjectUtils;

import java.util.function.Consumer;
import java.util.function.Supplier;

public class CacheUtil {
    public static <T> T getCache(Supplier<T> cacheData, Supplier<T> dbData, Consumer<T> saveData){
        T data = cacheData.get();
            if(ObjectUtils.isEmpty(data)){
                data = dbData.get();
                if(!ObjectUtils.isEmpty(data)){
                    saveData.accept(data);
                }
            }
        return data;
    }
}
